home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / file-tra / fsp-2.7 / fsp-2 / fsp / vms_src / convpath.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-14  |  3.3 KB  |  129 lines

  1. /* convpath.c
  2.  *
  3.  * Some awful Unix to VMS-directory conversion routines for use with
  4.  * VMS-fsp.
  5.  *
  6.  * 28-DEC-92 First version for VMS-FSP 2.6.5 <S.A.Pechler@bdk.tue.nl>
  7.  * 22-JAN-93 Added convdots routine <S.A.Pechler@bdk.tue.nl>
  8.  * 07-FEB-93 Optimized with SHELL$-routine <S.A.Pechler@bdk.tue.nl>
  9.  */
  10.  
  11. #include "common_def.h"
  12.  
  13. char *vms_name; /* global namespec */
  14.  
  15. int do_shell_filespec(fs)
  16. char *fs;
  17. {
  18.   vms_name=fs;
  19.   return(1);
  20. }
  21.  
  22. char *unixtovms(unixpath)
  23. char *unixpath;
  24. {
  25.   if (SHELL$TO_VMS(unixpath, do_shell_filespec, 1)) return(vms_name);
  26.   else return(NULL);
  27. }
  28.  
  29. #ifdef TEST
  30. /*
  31.  * convert unixpath to absolute VMS-path
  32.  * args: dest: vms-pathname
  33.  *       path: unix-style pathname
  34.  * ret:     0: conversion ok
  35.  *         -1: error.
  36.  */
  37. int convpath(dest,path)
  38. char *dest,*path;
  39. {
  40.  char *trans,*here;
  41.  
  42.  strcpy(dest,home_dir);     /* add home_dir always (absolute path) */
  43.  if (*path)                 /* something to convert? */
  44.  {
  45.    here=dest+strlen(dest);  /* find last char of string */
  46.    strcpy(here,path);       /* add path to it */
  47.    if (trans=unixtovms(here))  /* if conversion ok, */
  48.        strcpy(here-1,trans+1); /* put it back, strip trailing ']'
  49.                                   from trans and leading '[' from here */
  50.    else return(-1);            /* otherwise return error */
  51.  }
  52.  return(0);
  53. }
  54.  
  55.  
  56. /*
  57.  * convert unixdir to VMS-dirname
  58.  * args: dest: name of vms-directoryfile
  59.  *       path: unix-style directoryname
  60.  * ret:     0: conversion ok
  61.  *         -1: error.
  62.  */
  63. int convdir(dest,path)
  64. char *dest,*path;
  65.  
  66. {
  67.  char *trans,*here;
  68.  
  69.  if (*path)                 /* something to convert? */
  70.  {
  71.    strcpy(dest,path);       /* add path to it */
  72.    strcat(dest,".dir.1");   /* concatenate .dir.1 extension, so that it will
  73.                                be converted to a directory-filename */
  74.    if (trans=unixtovms(dest)) strcpy(dest,trans);   /* conv.ok? put it back */
  75.    else return(-1);           /* otherwise return error */
  76.  }
  77.  else                         /* empty path, so only home-directory */
  78.  {
  79.    if (getcwd(dest,512,0)) strcat(dest,".dir.1");
  80.    else return(-1);
  81.    if (trans=unixtovms(dest)) strcpy(dest,trans);
  82.    else return(-1);
  83.  }
  84.  return(0);
  85. }
  86. #endif
  87.  
  88. /*
  89.  * convert unixfilepath to VMS-filepath
  90.  * args: dest: name of vms-directoryfile
  91.  *       path: unix-style filepath
  92.  * ret:     0: conversion ok
  93.  *         -1: error.
  94.  */
  95. int convfile(dest,path)
  96. char *dest,*path;
  97. {
  98.  char *trans;
  99.  
  100.  if (!*path) return(-1);                 /* something to convert? */
  101.  if (!(trans=unixtovms(path))) return (-1); /* error during conversion */
  102.  strcpy(dest,trans);                     /* put it back */
  103.  return(0);
  104. }
  105.  
  106. /* convdots
  107.  * If more then 1 dot in filename, convert them to an underscore.
  108.  * If any invalid character in filename (exclamation marks, question marks,
  109.  * colons, etc.) , then convert it also to an underscore.
  110.  */
  111. int convdots(target,source)
  112. char *target,*source;
  113.  
  114. { char *dot,*here;
  115.  
  116.   strcpy(target,source);              /* make a copy first */
  117.   if (dot=strchr(target,'.'))       /* is there a dot present?*/
  118.      while (here=strchr(dot+1,'.')) /* look for more dots */
  119.      {
  120.        *here='_';                   /* replace with '_' */
  121.        dot=here;                    /* find next dot */
  122.      }
  123.   /* Convert invalid characters to an underscore */
  124.   here=target;
  125.   while (here=strpbrk(here,"?!:")) *here++='_';
  126.  
  127.   return(0); /* can't go wrong */
  128. }
  129.